<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/12/14
 * Time: 13:39
 */

namespace app\adminapiv3\service\platform_manage;



use app\adminapiv3\service\BaseService;
use app\adminapiv3\service\SystemConf;

class ServerProxyService extends BaseService
{
    /**
     * @name 获取代理配置
     * @return mixed
     * @author wx
     * @date 2019/12/14 14:17
     */
    public function getProxy()
    {
        $server = new  \app\common\service\platform_manage\ServerProxyService();
        $data = $server->getCommunicationIp();
        return $data;
    }


    /**
     * @name 逻辑处理
     * @param $ip
     * @param $port
     * @author wx
     * @date 2019/12/16 10:34
     */
    public function modifyCommon($ip)
    {
        $confServer = new SystemConf();

        $databaseConf = config('database.');

        //连接数据库测试
        $link = @mysqli_connect($ip, $databaseConf['username'], $databaseConf['password'],$databaseConf['database'], $databaseConf['hostport']);

        if (!$link){
            $this->setError($this->CODE_FAIL, '数据库连接失败!');
            return false;
        }

        //1. 修改PHP端数据库配置文件
//        $dbStr = $confServer->databaseConf($ip, $databaseConf['hostport'], $databaseConf['database'], $databaseConf['username'], $databaseConf['password']);
//        $dbConfFile = dirname($_SERVER['DOCUMENT_ROOT']).'/config/database.php';
//        file_put_contents($dbConfFile, $dbStr);


        //1. 清除原来的配置
        $server = new  \app\common\service\platform_manage\ServerProxyService();

        //2.修改配置
        $server->modify(['ip_type' => 2], ['ip' => $ip]);

    }


}